package com.atstudy.config;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.PropertySource;

import javax.sql.DataSource;

/**
 * @version v1.0
 * @description:
 * @author: admin
 * @date: 2023/2/13 13:40
 * @copyright: 博为峰
 */
@PropertySource("druid.properties")
public class DruidConfig {
    @Value("${mysql.driverClassName}")
    public String driverClassName;
    @Value("${mysql.url}")
    public String url;
    @Value("${mysql.username}")
    public String username;
    @Value("${mysql.password}")
    public String password;

    @Bean(name = "dataSource")
    public DataSource getDataSource() {
        DruidDataSource dataSource = new DruidDataSource();
        dataSource.setDriverClassName(driverClassName);
        dataSource.setUrl(url);
        dataSource.setUsername(username);
        dataSource.setPassword(password);
        return dataSource;
    }
}
